package cn.hpu.mobile_bank.controller;


import cn.hpu.mobile_bank.domain.PersonInfo;
import cn.hpu.mobile_bank.dto.resp.ApiResult;
import cn.hpu.mobile_bank.service.PersonInfoService;
import cn.hpu.mobile_bank.utils.RequestHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "个人信息管理")
@RequestMapping("/personInfo")
public class PersonInfoController {

    @Autowired
    private PersonInfoService personInfoService;
    @GetMapping("/get")
    @Operation(summary = "获取个人信息")
    public ApiResult<PersonInfo> getPersonInfo(){
        Integer personId = RequestHolder.get().getPersonId();
        return ApiResult.success(personInfoService.getById(personId));
    }

    @PostMapping("/update")
    @Operation(summary = "更新个人信息")
    public ApiResult<String> updatePersonInfo(@RequestBody PersonInfo personInfo){
        personInfo.setId(RequestHolder.get().getPersonId());
        personInfoService.updateById(personInfo);
        return ApiResult.success();
    }


}
